package sshTerm

import (
	"github.com/gorilla/websocket"
	"log"
	"net"
	"time"
)

// WebSSH 管理 Websocket 和 ssh 连接
type WebSSH struct {
	id                               string
	buffSize                         uint32
	term                             string
	sshConn                          net.Conn
	websocket                        *websocket.Conn
	connTimeout                      time.Duration
	logger                           *log.Logger
	DisableZModemSZ, DisableZModemRZ bool
	ZModemSZ, ZModemRZ, ZModemSZOO   bool
}

// NewWebSSH WebSSH 构造函数
func NewWebSSH() *WebSSH {
	return &WebSSH{
		buffSize:    DefaultBuffSize,
		logger:      DefaultLogger,
		term:        DefaultTerm,
		connTimeout: DefaultConnTimeout,
	}
}

// AddWebsocket 添加 websocket 连接
func (ws *WebSSH) AddWebsocket(conn *websocket.Conn, redisKey string) {
	ws.logger.Printf("(%s) websocket connected", ws.id)
	ws.websocket = conn
	go func() {
		ws.logger.Printf("(%s) websocket exit %v", ws.id, ws.server(redisKey))
	}()
}
